package org.huolala.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.huolala.dao.DriverDao;
import org.huolala.pojo.Driver;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/driver")
public class DriverController {
	@Resource
	private DriverDao driverDao;

	public void setDriverDao(DriverDao driverDao) {
		this.driverDao = driverDao;
	}
	
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public String login(String mobile, String password, HttpSession session) throws Exception {
		Driver driver = driverDao.login(mobile, password);
		if (driver != null) {
			session.setAttribute("login_driver", driver);
			return "redirect:/driver/main";
		}
		session.setAttribute("error", "手机号或者密码错误");
		return "redirect:/driver_login.jsp";
	}
	
	@RequestMapping(value="/regist",method=RequestMethod.POST)
	public String regist(Driver driver) throws Exception {
		driverDao.add(driver);
		return "redirect:/driver_login.jsp";
	}
	
	@RequestMapping("/main")
	public String main(ModelMap modelMap) throws Exception {
		return "driver/main";
	}
	
}







